package com.falcon.authority.controller;

import com.falcon.authority.domain.po.MenuComponentPO;
import com.falcon.authority.domain.req.MenuComponentQuery;
import com.falcon.authority.domain.req.MenuComponentRequest;
import com.falcon.authority.service.IMenuComponentService;
import com.falcon.core.controller.IBaseController;
import com.falcon.core.domain.BasePager;
import com.falcon.core.domain.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/authority/menuComponent")
@Tag(name = "MenuComponentController", description = "菜单组件表-接口")
public class MenuComponentController  implements IBaseController {

    @Autowired
    private IMenuComponentService menuComponentService;

    @Operation(summary = "新增")
    @PostMapping("/save")
    public BaseResponse<Long> save(@Valid @RequestBody MenuComponentRequest request) {

        Long id =  this.menuComponentService.save(request);

        return BaseResponse.success(id);
    }

    @Operation(summary = "修改")
    @PutMapping("/update/{id}")
    public BaseResponse<Boolean> update(@PathVariable Long id, @Valid @RequestBody MenuComponentRequest request) {

        Boolean success =  this.menuComponentService.update(id, request);

        return BaseResponse.success(success);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteById(@PathVariable Long id) {

        Boolean success =  this.menuComponentService.deleteById(id);

        return BaseResponse.success(success);
    }

    @Operation(summary = "批量删除")
    @PostMapping("/batchDelete")
    public BaseResponse<Integer> batchDelete(@RequestBody List<Long> ids) {

        Integer num =  this.menuComponentService.batchDelete(ids);

        return BaseResponse.success(num);
    }

    @Operation(summary = "查询基本信息")
    @GetMapping("/{id}")
    public BaseResponse<MenuComponentPO> detail(@PathVariable Long id) {

        MenuComponentPO MenuComponentPO =  this.menuComponentService.queryById(id);

        return BaseResponse.success(MenuComponentPO);
    }


    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public BaseResponse<List<MenuComponentPO>> list(@RequestBody MenuComponentQuery request) {

        List<MenuComponentPO> list =  this.menuComponentService.queryList(request);

        return BaseResponse.success(list);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/pager")
    public BaseResponse<BasePager<MenuComponentPO>> pager(@RequestBody MenuComponentQuery request) {

        BasePager<MenuComponentPO> pager =  this.menuComponentService.queryPager(request);

        return BaseResponse.success(pager);
    }


}

